package com.ceba.test.modules.admin.dao;

import com.ceba.base.web.dao.IBaseDao;

import abc.data.DataTable;
import abc.data.Sql;
import abc.data.SqlSessionManager;

public class OrganizeDao extends IBaseDao{
	
	public boolean hasChildOrganize(String departId) {
		Sql sql = new Sql("select * from u_department where PID = '" + departId+"'");
		DataTable table = SqlSessionManager.getDataTable(sql);
		if(table != null && table.getRowCount() >0){
			return true;
		}
		return false;
	}

	public boolean hasUserInOragnize(String departId) {
		Sql sql = new Sql("select * from u_user where department_ID = '" + departId+"'");
		DataTable table = SqlSessionManager.getDataTable(sql);
		if(table != null && table.getRowCount() >0){
			return true;
		}
		return false;
	}

	public boolean deleteOrganize(String departId) {
		Sql sql = new Sql("delete from u_department where ID = '" + departId+"' or PID = '" +departId+ "'");
		return  SqlSessionManager.execute(sql);
	}

	//强制删除该部门的子部门以及子用户
	public boolean deleteForceOrganize(String departId) {
		Sql sql = new Sql("delete from u_user where department_ID = '"+departId+"' or department_ID in "
				+ " (select ID from u_department where PID = '" + departId+"')");
		boolean flag = SqlSessionManager.execute(sql);
		if(flag){
			flag = deleteOrganize(departId);
		}
		return flag;
	}

}
